{include file="public/header"}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员信息备注</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" name="data[nickname]" value="{$data.nickname|default=''}"
                            required="" lay-verify="required" autocomplete="off" class="layui-input">
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span> 备注，方便快速记录用户
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员账号</label>
                    <div class="layui-input-block">
                        <input type="text" id="username" name="data[username]" value="{$data.username|default=''}"
                            required="" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="text" id="password" name="data[password]" value="" autocomplete="off"
                            class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>密码若不填写不修改密码
                    </div>
                </div>
                {foreach :config('menu.menu') as $k => $v}
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label">{$v.name}</label>
                    <div class="layui-input-block">
                        {foreach $v.sub as $x => $y}
                        <input name="data[role][]" type="checkbox" value="{$y.uri}" title="{$y.name}" {if
                            isset($data.role) && in_array($y.uri, $data.role)} checked {/if}>
                        {/foreach}
                    </div>
                </div>
                <hr />
                {/foreach}
                <input type="hidden" value="{$data['id']|default='0'}" name="data[id]" />
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn  layui-btn-normal" lay-submit="" lay-filter="add">提交</button>
                        <button type="reset" class="layui-btn layui-btn-warm">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    {include file="public/footer"}

    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;
            //监听提交
            form.on('submit(add)', function (data) {
                //发异步，把数据提交给php
                $.ajax({
                    'type': 'post',
                    data: data.field,
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });
            form.on('checkbox(father)', function (data) {
                if (data.elem.checked) {
                    $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                    form.render();
                } else {
                    $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                    form.render();
                }
            });


        });
    </script>